package com.tedu.notice.controller;

import com.tedu.common.response.JsonResult;
import com.tedu.notice.pojo.dto.NoticeDto;
import com.tedu.notice.pojo.vo.NoticeVo;
import com.tedu.notice.service.NoticeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@CrossOrigin(origins = "http://your-frontend-domain")
@Slf4j
@RestController
@RequestMapping("v1/property/notice")
public class NoticeController {
    @Autowired
    NoticeService noticeService;


    @RequestMapping("select")
    public JsonResult selectNotice(NoticeDto noticeDto){
        log.debug("开始处理【查询公告】的请求，参数={}", noticeDto);
        List<NoticeVo> list = noticeService.selectNotice(noticeDto);
        log.debug("查询结果={}", list);
        return JsonResult.ok(list);
    }

    @RequestMapping("save")
    public JsonResult saveNotice(NoticeDto noticeDto){
        log.debug("开始处理【上传公告】的请求，参数={}", noticeDto);
        noticeService.saveNotice(noticeDto);
        return JsonResult.ok();
    }

    @RequestMapping("delete/{noticeId}")
    public JsonResult deleteNotice(@PathVariable Integer noticeId){
        log.debug("开始处理【删除公告】的请求，参数={}", noticeId);
        noticeService.deleteNotice(noticeId);
        return JsonResult.ok();
    }
    @RequestMapping("update")
    public JsonResult updateProperty(NoticeDto noticeDto){
        log.debug("开始处理【审核公告申请】的请求，参数={}", noticeDto);
        noticeService.updateProperty(noticeDto);
        return JsonResult.ok();
    }
}

